#include<ctime>
#include<iostream>
#include"StringPool.h"

void StringPool::addString(int number){
	for(int i = 0; i < number; i++){
		pool->push_back(new string());
	}
}

StringPool::StringPool(int size){
	pool = new vector<string*>(size);
	for(int i = 0; i < size; i++){
		(*pool)[i] = new string();
	}
}

StringPool::~StringPool(){
	int size = (int)(pool->size());
	for(int i = 0; i < size; ++i){
		delete((*pool)[i]);
	}
	delete(pool);
}

string* StringPool::get(string &s){
	/*
	if(pool->empty()){
		addString(1000000);
		cout<<"alloc another 1000000"<<endl;
	}
	int size = (int)(pool->size());
	string* str = (*pool)[size - 1];
	*str = s;
	pool->pop_back();

	int length = (int)(str->size());
	int capacity = (int)(str->capacity());
	if(length != capacity){
		printf("%d %d %s\n", length, capacity, str->c_str());
		system("pause");
	}
	*/

	string* str = new string(s);
	return str;
}

string* StringPool::get(){
	string str = "";
	return get(str);
}

void StringPool::push_back(std::string *str){
	delete(str);
	//pool->push_back(str);
}

int StringPool::size(){
	return (int)(pool->size());
}
	
	
